package com.hb.software.user.impl;

import com.hb.software.entity.user.User;
import com.hb.software.service.impl.BaseServiceImpl;
import com.hb.software.user.UserService;
import com.hb.software.user.dao.UserDao;
import com.hb.software.worker.dao.WorkerDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl extends BaseServiceImpl<User,Long> implements UserService {


    private UserDao userDao;
    @Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
        this.dao = this.userDao;
    }
    @Override
    public Long selectAmount(){
        return userDao.selectCount();
    }

    @Override
    public User selectRole(String adminnum) {
        return null;
    }

    @Override
    public void updateRole(User user) {
        userDao.updateRole(user);
    }

    @Override
    public void delete(Long id) {
        userDao.delete(id);
    }

    @Override
    public void update(User login){
        userDao.update(login);
    }


    @Override
    public User findById(Long id) {
        return userDao.findOne(id);
    }

    @Override
    public User login(User user) {
        User userDB = userDao.findByUsername(user.getUsername());
        if (userDB != null) {
           if (userDB.getPassword().equals(user.getPassword())) {
                return userDB;
            }
            throw new RuntimeException("密码输入错误~~~");
        } else {
            throw new RuntimeException("用户名输入错误!!!");
        }
    }

}
